﻿class cn.eminia.AS2.DebugPannel {
	var tf, caption, corner, cH = 20;
	var doubleClickSpeed = 250;
	var clickInterval;
	function DebugPannel(o, pos, size, cH) {
		this.cH = (cH == undefined) ? this.cH : cH;
		caption = create矩形(o, [size[0], cH], [0, 0], 'caption', 0x0000FF, 100);
		tf = createTf(o, size, [0, cH], 'tf');
		corner = create矩形(o, [20, 20], [size[0]-10, size[1]+10], 'corner', 0x000000, 0);
		addDrag(caption);
		addMS(corner);
	}
	function addMS(o) {
		o.$ = this;
		o.onMouseDown = function() {
			//!this.boundingBox_mc.hitTest(_root._xmouse, _root._ymouse) &&slectTf
			var x = _root._xmouse;
			var y = _root._ymouse;
			if (this.hitTest(x, y)) {
				//this.startDrag(true, 0, 0,10000,10000);
				this.startDrag();
				this.onEnterFrame = function() {
					this._parent.caption._width = this._parent.tf._width=this._x+10;
					this._parent.tf._height = this._y+10-this.$.cH;
					//this._parent.tf._height = this._y+10+this.$.cH;
				};
				//this.onMouseDown = undefined;
				this.openOrClose(false);
			}
		};
		o.onMouseUp = function() {
			var x = _root._xmouse;
			var y = _root._ymouse;
			if (this.hitTest(x, y)) {
				this.stopDrag();
				delete this.onEnterFrame;
			}
		};
	}
	function createTf(mc, wh, xy, name) {
		var o = mc.createTextField(name, mc.getNextHighestDepth(), xy[0], xy[1], wh[0], wh[1]);
		o.border = true;
		o.background = true;
		o.multiline = true;
		return o;
	}
	function create矩形(mc, wh, xy, name, clr, alpha) {
		xy = (xy == undefined) ? [0, 0] : xy;
		var fix = xy[2];
		alpha = (alpha == undefined) ? 100 : alpha;
		var o = mc.createEmptyMovieClip(name, mc.getNextHighestDepth());
		if (fix == undefined) {
			o._x = xy[0];
			o._y = xy[1];
			xy[0] = xy[1]=0;
		} else {
			o._x = o._y=0;
		}
		o.beginFill(clr, alpha);
		//o.lineStyle(0, 0xFF00FF, 100);
		o.moveTo(xy[0], xy[1]);
		//设置开始点的坐标。
		o.lineTo(xy[0]+wh[0], xy[1]);
		o.lineTo(xy[0]+wh[0], xy[1]+wh[1]);
		o.lineTo(xy[0], xy[1]+wh[1]);
		o.lineTo(xy[0], xy[1]);
		//设置结束点坐标，整个矩形绘制完毕
		o.endFill();
		//设置线条的粗细，颜色和透明度
		return o;
	}
	function addDrag(mc) {
		mc.onPress = function() {
			var currTime = getTimer();
			var diff = currTime-this.lastTime;
			if (diff<200) {
				this._parent.corner._visible = this._parent.tf._visible=(this._parent.tf._visible) ? false : true;
			} else {
				this._parent.startDrag();
			}
			this.lastTime = currTime;
		};
		mc.onRelease = function() {
			this._parent.stopDrag();
		};
	}
	function set text(a) {
		this.tf.text += '\r'+a;
	}
	function set _visible(a) {
		this.tf._visible = a;
		this.caption._visible = a;
	}
	function autoVisible() {
		this.tf._visible = this.tf._visible ? false : true;
		this.caption._visible = this.caption._visible ? false : true;
	}
	function trace(a) {
		this.tf.text += '\r'+a;
	}
}
